package com.hujf.flink.window.TimeWindow;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author hujf
 * @Date 2022/5/23 14:58
 * @Description TODO
 */
public class TumblingCountWind {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment environment = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStream<Tuple2<String, Integer>> source = environment.fromElements(
                Tuple2.of("s1", 1),
                Tuple2.of("s2", 3),
                Tuple2.of("s3", 4),
                Tuple2.of("s4", 5),
                Tuple2.of("s1", 1),
                Tuple2.of("s4", 1),
                Tuple2.of("s2", 4),
                Tuple2.of("s4", 1),
                Tuple2.of("s4", 2),
                Tuple2.of("s3", 1)


        );
        SingleOutputStreamOperator<Tuple2<String, Integer>> sum = source.keyBy(0)
                .countWindow(3,2)
                .sum(1);

        sum.print();
        environment.execute();

    }
}
